home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / src / Tools / vg-2.03 / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-03  |  3.1 KB  |  190 lines

  1. /*
  2.  * Copyright (C) 1990-1992 Michael Davidson.
  3.  * All rights reserved.
  4.  *
  5.  * Permission to use, copy, modify, and distribute this software
  6.  * and its documentation for any purpose and without fee is hereby
  7.  * granted, provided that the above copyright notice appear in all
  8.  * copies and that both that copyright notice and this permission
  9.  * notice appear in supporting documentation.
  10.  *
  11.  * This software is provided "as is" without express or implied warranty.
  12.  */
  13.  
  14. /*
  15.  * GIF file viewer for SCO UNIX 
  16.  */
  17.  
  18. /*
  19.  * The Graphics Interchange Format(c) is the Copyright property
  20.  * of CompuServe Incorporated.
  21.  *
  22.  * GIF(sm) is a Service Mark property of CompuServe Incorporated.
  23.  */
  24.  
  25.  
  26. #include    <stdio.h>
  27. #include    <stdlib.h>
  28. #include    <signal.h>
  29. #include    <unistd.h>
  30.  
  31. #include    "vg.h"
  32. #include    "kbd.h"
  33. #include    "video.h"
  34.  
  35. char        *cmdname        = NULL;
  36. char        *display        = NULL;
  37. int        nomenu            = 0;
  38. int        vflag            = 0;
  39. int        tflag            = 0;
  40. int        menuwidth        = 80;
  41. int        maxdepth        = 24;
  42. char        *InitialDirectory    = NULL;
  43. char        *CurrentDirectory    = NULL;
  44.  
  45. int
  46. main(
  47.     int        argc,
  48.     char    **argv
  49.     )
  50. {
  51.     int        c;
  52.     list_t    *f;
  53.     void    sigcatch(int sig);
  54.     extern int    optind;
  55.     extern char    *optarg;
  56.     extern void    showUsage();
  57.  
  58.     cmdname    = argv[0];
  59.  
  60.     if (argc < 2)
  61.     {
  62.     showUsage();
  63.     return 0;
  64.     }
  65.  
  66.     display    = getenv("VG_DISPLAY");
  67.  
  68.     while ((c = getopt(argc, argv, "1:d:ntvw:x:z")) != EOF)
  69.     {
  70.     switch (c)
  71.     {
  72.         case '1':
  73.         menuwidth = 132;
  74.         break;
  75.  
  76.         case 'n':
  77.         ++nomenu;
  78.         break;
  79.  
  80.         case 'd':
  81.         display = optarg;
  82.         break;
  83.  
  84.         case 't':
  85.         ++tflag;
  86.         break;
  87.  
  88.         case 'v':
  89.         ++vflag;
  90.         break;
  91.  
  92.         case 'w':
  93.         imageSetDefaultDelay(atoi(optarg));
  94.         break;
  95.  
  96.         case 'x':
  97.         maxdepth = atoi(optarg);
  98.         break;
  99.  
  100.         default:
  101.         break;
  102.     }
  103.     }
  104.  
  105.     if (! vflag && ! tflag)
  106.     {
  107.     if ((f = fileListCreate(&argv[optind]))  == NULL)
  108.         fatal(0, "can't create file list");
  109.  
  110.     f = fileListSort(f);
  111.     }
  112.  
  113.     if (signal(SIGINT, sigcatch) == SIG_IGN)
  114.     fatal(0, "%s cannot be run in the background", cmdname);
  115.  
  116.     InitialDirectory = getcwd(NULL, 1024);
  117.     CurrentDirectory = InitialDirectory;
  118.  
  119.     signal(SIGHUP, sigcatch);
  120.     signal(SIGTERM, sigcatch);
  121.     signal(SIGBUS, sigcatch);
  122.     signal(SIGSEGV, sigcatch);
  123.     signal(SIGFPE, sigcatch);
  124.  
  125.     vidInit(display);
  126.     kbdInit();
  127.     imageInit();
  128.     ycc_rgb_init();
  129.  
  130.     setuid(getuid());
  131.  
  132.     if (tflag)
  133.     testMenu();
  134.     else if (! vflag)
  135.     fileMenu(f);
  136.  
  137.     kbdReset();
  138.     vidReset();
  139.  
  140.     if (vflag)
  141.     showConfig();
  142.  
  143.     return 0;
  144. }
  145.  
  146. void
  147. sigcatch(
  148.     int        sig
  149.     )
  150. {
  151.     cleanup();
  152.  
  153.     if (sig != SIGINT)
  154.     fprintf(stderr, "%s: caught signal %d\n", cmdname, sig);
  155.  
  156.     exit(sig);
  157.  
  158.     /*NOTREACHED*/
  159. }
  160.  
  161. void
  162. cleanup()
  163. {
  164.     static int    cleaning_up    = 0;
  165.  
  166.     if (cleaning_up)
  167.     fprintf(stderr, "%s: recursive call to Cleanup()\n", cmdname);
  168.     else
  169.     {
  170.     cleaning_up    = 1;
  171.     if (InitialDirectory != NULL)
  172.         chdir(InitialDirectory);
  173.     kbdReset();
  174.     vidReset();
  175.     cleaning_up    = 0;
  176.     }
  177. }
  178.  
  179. showConfig()
  180. {
  181.     vmode_t    *v;
  182.  
  183.     printf("%s\n", vidGetName());
  184.  
  185.     for (v = vidGetModes(); v->flags != 0; v++)
  186.     if (v->flags & V_MODE_SUPPORTED)
  187.         printf("%dx%d-%d %s\n", v->width, v->height, v->depth,
  188.             (v->flags & V_GRAPHICS_MODE) ? "graphics" : "text");
  189. }
  190.